﻿using Comm.Model;
using Comm.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Comm.Web.Action
{
    /// <summary>
    /// getBackPwd 的摘要说明
    /// </summary>
    public class getBackPwd : BaseHander
    {
        BLL.MiBaoService bllmibao = new BLL.MiBaoService();
        BLL.MBQuestionService bllquestion = new BLL.MBQuestionService();
        BLL.UsersService blluser = new BLL.UsersService();
        public override void SonLoad()
        {
            string type =Request.Params["type"];
            switch (type) 
            {
                case "mibao":
                    getmiBao();
                    break;
                case "password":
                    UpdatePwd();
                    break;
            }
        }
        public void getmiBao() 
        {
            commom.GetMibao<MiBao> model = new commom.GetMibao<MiBao>() 
            {
                 GetMbQuestionList=bllquestion.getMBquestion(),
                 GetMibaoList = bllmibao.getAllMiBao(UserNow.uId)
            };
            try
            {
                if (model != null) 
                {
                    AjaxMsgHelper.AjaxMsg("ok", "加载成功！~~", JsonHelper.Serialize(model));
                }              
            }
            catch (Exception ex)
            {

                AjaxMsgHelper.AjaxMsg("err", "加载失败！~~", JsonHelper.Serialize(ex.Message));
            }
            
        }

        public void UpdatePwd() 
        {
            Model.Users model = new Model.Users()
            {
                uLoginName = UserNow.uLoginName,
                uPwd = Request.Form["pwd1"].Md5().ToUpper(),
                uIsDel = false,
                uId = UserNow.uId,
                Phone = UserNow.Phone,
                Mail = UserNow.Mail,
                Address = UserNow.Address,
                otherName = UserNow.otherName

            };
            blluser.Update(model);
            string url = "../html/login.html";
            AjaxMsgHelper.AjaxMsg("ok", "密码重置成功！~~", JsonHelper.Serialize(url));
            

        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}